/**
 * 精确的 setTimeout 实现
 */
export function preciseTimeout(callback, interval) {
  const startTime = Date.now();  // 获取当前时间
  function loop() {
    const elapsedTime = Date.now() - startTime;  // 计算过去的时间
    const delay = Math.max(0, interval - (elapsedTime % interval));  // 计算下次的延迟时间
 
    setTimeout(function() {
      callback();
      loop();  // 递归调用，以保持精度
    }, delay);
  }
  
  loop();
}

export function durationFormatter(time) {
  if (!time) return { dd:0,hh:0,mm:0,ss: 0 };
  let t = time;
  const ss = t % 60;
  t = (t - ss) / 60;
  if (t < 1) return { dd:0,hh:0,mm:0,ss };
  const mm = t % 60;
  t = (t - mm) / 60;
  if (t < 1) return { dd:0,hh:0,mm,ss };
  const hh = t % 24;
  t = (t - hh) / 24;
  if (t < 1) return { dd:0,hh,mm,ss };
  const dd = t;
  return { dd, hh, mm, ss };
}